package log_lib

import (
	"fmt"
	"github.com/beego/beego/v2/core/logs"
	beego "github.com/beego/beego/v2/server/web"
	"os"
	"time"
)

func InitLog() {
	var runmode, _ = beego.AppConfig.String("runmode")
	year, month, day := time.Now().Date()
	fileName := fmt.Sprintf("./log/%d-%d-%d.log", year, month, day)
	err := os.MkdirAll("./log", 0777)
	if err != nil {
		logs.Error("mkdir ./log failed, err:%v", err)
	} else {
		logs.Info("log file to %s", fileName)
	}
	if runmode == "debug" {
		logs.EnableFullFilePath(true)
	}
	logs.SetLogFuncCall(true)
	_ = logs.SetLogger(logs.AdapterConsole)
	cc := `{"filename":"` + fileName + `","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10,"color":true}`
	_ = logs.SetLogger(logs.AdapterFile, cc)

}
